﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Tomahawk.Runtime.Rendering;
using Tomahawk.Runtime.Input;

namespace Tomahawk.Runtime.Components
{
    public class InfoParameters : OverlayParameters
    {
    }

    /// <summary>
    /// A reusable component for adding an info screen for debugging purposes
    /// </summary>
    public class InfoComponent : OverlayComponent
    {
        #region Instance
        private static InfoComponent instance = null;
        public static InfoComponent Instance { get { return instance; } }
        #endregion

        #region Fields
        public class InfoEntry
        {
            public int X = 0;
            public int Y = 0;
            public string text = "";
            public Color color = Color.White;
        }

        protected Dictionary<string, InfoEntry> info = new Dictionary<string, InfoEntry>();
        public Dictionary<string, InfoEntry> Info { get { return info; } } 
        #endregion

        #region Initialization
        public static void Register(Game game, ref InfoParameters parameters)
        {
            if (parameters.enabled)
            {
                Vector2 basePos = Vector2.Zero;
                basePos.X = parameters.X;
                basePos.Y = parameters.Y;
                instance = new InfoComponent(basePos, game);

                game.Components.Add(instance);
            }
        }

        protected InfoComponent(Vector2 basePos, Game game)
            : base(basePos, game)
        {
        }
        #endregion

        #region Update
        protected override void OnUpdate(GameTime gameTime)
        {
        }
        #endregion

        #region Draw
        protected override void OnDraw2D(GameTime gameTime)
        {
            foreach (KeyValuePair<string, InfoEntry> pair in info)
            {
                Color color = pair.Value.color;
                DrawString(pair.Value.X, pair.Value.Y, pair.Value.text, ref color);
            }
        }

        protected override void OnDraw3D(GameTime gameTime)
        {
        }
        #endregion
    }
}
